package roborally.script.composedCondition;

import exception.IllegalScriptSyntaxException;
import roborally.model.Robot;
import roborally.script.ComposedCondition;
import roborally.script.Condition;
import be.kuleuven.cs.som.annotate.*;
import be.kuleuven.cs.som.taglet.*;

/**
 * @author Joren VERSPEURT
 * @author Mathieu REYMOND
 * @version 3.0
 * 
 * The class representing a Not statement in the RoboRally script language.
 */
public class Not extends ComposedCondition {

	/**
	 * Creates a new Not-condition with a given Robot. This Condition is composed by one and only one sub-condition (that is given as parameter).
	 * @param robot The Robot this Condition will apply to.
	 * @param conditions The sub-condition of this Not statement.
	 * @throws IllegalScriptSyntaxException This Condition must be composed by one and only one sub-condition
	 */
	public Not(Robot robot, Condition... conditions) throws IllegalScriptSyntaxException{
		super(robot, conditions);
		if(conditions.length != 1) throw new IllegalScriptSyntaxException("A not statement must have 1 and only one condition.");
	}

	/**
	 * A Not statement's state is the opposite of its sub-condition's state,
	 * <code>true</code> if the sub-condition is <code>false</code>, false otherwise.
	 */
	@Override
	public boolean isTrue() {
		return !getConditions().get(0).isTrue();
	}
	
	/**
	 * The script word for this condition.
	 */
	@Override
	public String toString() {
		return "not";
	}

}
